package com.xbh.boot_study.interceptor;

import com.xbh.boot_study.srv.HelloSrv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.context.request.WebRequestInterceptor;

public class MyWebRequestInterceptor implements WebRequestInterceptor {

    @Autowired
    HelloSrv helloSrv;

    @Override
    public void preHandle(WebRequest webRequest) throws Exception {
        WebRequest wr = webRequest;
        System.out.println("preHandle···");
    }

    @Override
    public void postHandle(WebRequest webRequest, ModelMap modelMap) throws Exception {
        WebRequest wr = webRequest;
        ModelMap mop = modelMap;
        System.out.println("postHandle···");
    }

    @Override
    public void afterCompletion(WebRequest webRequest, Exception e) throws Exception {
        // HttpServletRequest request = ((DispatcherServletWebRequest) webRequest).getRequest();
        // RequestLog requestLog = new RequestLog();
        // requestLog.setIp(request.getRemoteAddr());
        // requestLog.setPort(String.valueOf(request.getRemotePort()));
        // helloSrv.addOne(requestLog);
        System.out.println("afterCompletion···");
    }
}
